/**
 * 
 */
package AgentTravel.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.border.Border;

/**
 * @author Piotrek
 *
 */
public class Calendar extends JList {

	/**
	 * 
	 */
	private static final long serialVersionUID = 919469319779439191L;

	/**
	 * 
	 */
	public Calendar() {
		init();
	}

	/**
	 * @param arg0
	 */
	public Calendar(ListModel arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
		init();
	}

	/**
	 * @param arg0
	 */
	public Calendar(Object[] arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
		init();
	}

	private void init()
	{
		DayRenderer renderer = new DayRenderer();
        //renderer.setPreferredSize(new Dimension(30, 30));
        setCellRenderer(renderer);
        setSelectionBackground(Color.red);
        setSelectionForeground(Color.yellow);
        validate();
        setLayoutOrientation(JList.HORIZONTAL_WRAP);
        setVisibleRowCount(5);
	}
	/**
	 * @param arg0
	 */
	public Calendar(Vector<?> arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
	}

	private class DayRenderer extends JLabel implements ListCellRenderer{
		private Border brd = BorderFactory.createMatteBorder(1, 1, 1, 1, Color.black);
        /**
         * new cell rendered
         */
        public DayRenderer() {
            setOpaque(true);
            setHorizontalAlignment(CENTER);
            setBorder(brd);
        }

        /**
         * cell render callback
         * @param list
         * @param value
         * @param index
         * @param isSelected
         * @param cellHasFocus
         * @return component
         */
        public Component getListCellRendererComponent(JList list,
                Object value,
                int index,
                boolean isSelected,
                boolean cellHasFocus) {

            if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
            } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
            }

            setBackground(Color.cyan);
            setText(value.toString());

            return this;
        }
        
    }
}
